<template lang="pug">
  div.table-empty
    s-table(
      ref="table"
      :reqUrl="tableObj.url"
      reqMethod="POST"
      style="padding: 0"
      :column="tableObj.columnConfig"
      :filterProps="{fields: seachConfig}"
    )
      template(slot="action" slot-scope="text, scope")
        el-link(:underline="false" type="success" @click="() => addHandle(scope, 'detail')") 查看
      template(slot="checkDate" slot-scope="text, scope")
        span {{text | dateFilter('YYYY/MM/DD')}}
    check-detail(:visible.sync="chosedObj.visible" :id="chosedObj.id" :name="chosedObj.name")
</template>

<script>
import CheckDetail from './components/checkDetail'
import {
  checkResultColumnConfig
} from './config'
import { getTypeList } from './api'
import dayjs from 'dayjs'
export default {
  components: {
    CheckDetail
  },
  data () {
    return {
      typeList: [],
      chosedRow: {
        startTime: dayjs(Date.now()).format('YYYY-MM-DD'),
        endTime: dayjs(Date.now()).format('YYYY-MM-DD')
      },
      chosedObj: {
        visible: false,
        id: '',
        name: ''
      }
    }
  },
  computed: {
    tableObj () {
      return {
        url: 'api/xj_target_record/area_count',
        columnConfig: checkResultColumnConfig
      }
    },
    seachConfig () {
      const { chosedRow } = this
      return [
        {
          key: 'type',
          label: '检查类别',
          type: 'select',
          fieldProps: {
            options: this.typeList,
            props: { value: 'typeName', label: 'typeName' }
          }
        },
        {
          key: 'name',
          label: '检查时间',
          key1: 'startTime',
          key2: 'endTime',
          type: 'daterange',
          fieldProps: {
            style: {
              width: '256px'
            }
          },
          initialValue: [chosedRow.startTime, chosedRow.endTime]
        }
      ]
    }
  },
  created () {
    this.getTypeList()
  },
  methods: {
    getTypeList () {
      getTypeList({ pageNum: 0, pageSize: 99 }).then(res => {
        console.log(res)
        this.typeList = res.content
      })
    },

    addHandle (res) {
      this.chosedObj = {
        id: res.id,
        name: res.name,
        visible: true
      }
    }
  }
}
</script>

<style scoped>

</style>
